//
//  SBBaseTextField.m
//  SBAdaptiveTool
//
//  Created by user on 2018/9/10.
//  Copyright © 2018年 陈振旭. All rights reserved.
//

#import "SBBaseTextField.h"

#import "AdaptiveHeader.h"

@implementation SBBaseTextField

-(void)awakeFromNib {
    [super awakeFromNib];
    
    [self setFont:[UIFont fontWithDescriptor:[self.font fontDescriptor] size:SBScaleNumber(self.font.pointSize)]];
    
}


#pragma mark - 设置属性

- (void)setSBBorderColor:(UIColor *)SBBorderColor {
    if (!SBBorderColor) return;
    self.layer.borderColor = SBBorderColor.CGColor;
}

- (void)setSBCornerRadius:(CGFloat)SBCornerRadius {
    if (!SBCornerRadius) return;
    self.layer.cornerRadius = SBScaleNumber(SBCornerRadius);
}

- (void)setSBBorderWidth:(CGFloat)SBBorderWidth {
    if (!SBBorderWidth) return;
    self.layer.borderWidth = SBScaleNumber(SBBorderWidth);
}

- (void)setSBMasksToBounds:(BOOL)SBMasksToBounds {
    self.layer.masksToBounds = SBMasksToBounds;
}

- (void)setCursorLocation:(CGFloat)cursorLocation {
    _cursorLocation = cursorLocation;
}

//控制显示文本的位置
-(CGRect)textRectForBounds:(CGRect)bounds {
    CGRect inset = CGRectMake(bounds.origin.x+_cursorLocation, bounds.origin.y, bounds.size.width -_cursorLocation, bounds.size.height);
    return inset;
}

//控制编辑文本的位置
-(CGRect)editingRectForBounds:(CGRect)bounds {
    CGRect inset = CGRectMake(bounds.origin.x +_cursorLocation, bounds.origin.y, bounds.size.width -_cursorLocation, bounds.size.height);
    return inset;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
